<%--
  Created by IntelliJ IDEA.
  User: 乔波
  Date: 2021/4/16
  Time: 14:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <%--<script type="text/javascript" src="js/jquery2.js"></script>--%>
    <%--<script type="text/javascript" src="js/jquery2.sorted.js"></script>--%>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/ckform.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <style type="text/css">
        body {
            font-size: 20px;
            padding-bottom: 40px;
            background-color: #e9e7ef;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media ( max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form id="form1" class="form-inline definewidth m20" action="#" method="get">
    <font color="#777777"><strong>查询评价：</strong></font>
    <input type="text" name="evaconent" id="evaconent" class="abc input-default " value="">&nbsp;&nbsp;
    <button type="button" class="btn btn-primary ">查询</button>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr align="center">
        <th>博客标题</th>
        <th>评价内容</th>
        <th>评论人</th>
        <th>评论日期</th>
        <th>管理菜单</th>
    </tr>
    </thead>
    <tbody id="tbody">
    <%--存放行数据--%>
    </tbody>
    <tfoot id="tfoot">
    <%--设置分页信息--%>
    </tfoot>
</table>

<script type="text/javascript">

    $(function () {
        //***test全查
        findAll();
        //删除
        logout();
        //模糊查询
        findByEvaConent();
    });

    //**************************
    function findAll() {
        $.ajax({
            type: "POST",
            url: "/evaluate/findAll",
            dataType: "json",
            success: function (result) {
                $(result).each(function (index, rs) {
                    var $tr = ` <tr>
                                    <td style="display: none">` + rs.eid + `</td>
                                    <td>` + rs.econtent + `</td>
                                    <td>` + rs.blog.btitle + `</td>
                                    <td><a href="user_detail.jsp?uid=` + rs.user.uid + `">` + rs.user.uname + `</a></td>
                                    <td>` + rs.etime + `</td>
                                    <td><button class="logout">注销</button></td>
                                    </tr>`;
                    $("#tbody").append($tr);
                })
            }
        });
    }

    //注销功能：
    function logout() {
        $(document).on("click", ".logout", function (result) {
            var flag = window.confirm("您确定要删除该账户吗？");
            if (flag) {
                //获得用户的id：      $(this)点击的组件。 button
                var eid = $(this).parents("tr").children().eq(0).text();
                //发送ajax请求：
                $.get("/evaluate/deleteByEid?eid=" + eid, function (result) {
                    console.info(result);
                    if (result.msg) {//删除成功
                        alert(result.msg);
                        //重新加载页面：
                        window.location.reload();
                    } else {
                        alert(result.error);
                    }
                });
            }
        })
    }

    //*************************
    //根据用户名称模糊查询
    function findByEvaConent() {
        $(".btn").click(function () {
            //获得input框的值：
            var evaconent = $("#form1").serialize();
            //清空tbody：
            $("table tbody").empty();
            //发送异步请求
            $.post("evaluate/findByEvaConent", evaconent, function (result) {
                $(result).each(function (index, item) {
                    var $tr = ` <tr>
                                <td style="display: none">` + item.eid + `</td>
                                <td>` + item.blog.btitle + `</td>
                                <td>` + item.econtent + `</td>
                                <td><a href="user_detail.jsp?uid=` + item.user.uid + `">` + item.user.uname + `</a></td>
                                <td>` + item.etime + `</td>
                                <td><button  class="logout">注销</button></td>
                            </tr>`;
                    $("#tbody").append($tr);
                });
            });
        });
    }
</script>
</body>
</html>
